#pragma once
#include "Mutex.hpp"

#include <iostream>
using namespace ve;
namespace VE
{
    class Cond
    {
    private:
        pthread_cond_t _cond;
    public:
        Cond()
        {
            pthread_cond_init(&_cond, nullptr);
        }
        void wait(Mutex& mutex)
        {
            int n = pthread_cond_wait(&_cond, mutex.getmutex());
            (void)n;
        }
        void signal() // 唤醒在该条件变量下等待的一个线程
        {
            int n = pthread_cond_signal(&_cond);
            (void)n;
        }
        void broadcast() // 唤醒该条件变量下的所有线程
        {
            int n = pthread_cond_broadcast(&_cond);
            (void)n;
        }
        ~Cond()
        {
            pthread_cond_destroy(&_cond);
        }
    };

}